package com.uft.was.app;

import java.util.Calendar;
import java.util.HashMap;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;


public class WasAppManager {
	private  static Logger  logger = Logger.getLogger(WasAppManager.class);
	private String id;
	private String serverName;
	private StringBuffer outputBuffer;
	private StringBuffer errorBuffer;
	private boolean running = false;
	private Calendar startTime;
	private Calendar endTime;
	private int errorCode=-1;
	private String action;
	private boolean remoteExecute=false;
	private String hostname;
	private String port;
	private boolean security;
	private String dmgrUsername;
	private String dmgrPassword;
	private String scriptPath;
	private String serverPrefix;
	private String serverSuffix;
	private WasDeployCommand wasDeployCommand;
	
	
	public boolean addDeploymentTask(HashMap<String, String> options){
		action="DEPLOY";
		logger.info("Adding Deployment task:  "+id);
		if(!running){ 
			clearOutput();
			clearError();
			getWasDeployCommand().setArguments(options);
			getWasDeployCommand().start();
			logger.info("Adding Deployment task... OK");
			return true;
		}else{
			logger.warn("Deployment Taslk already running!.."+id);
		}
		
		return false;
		
	}
	public WasDeployCommand getWasDeployCommand(){
		if(wasDeployCommand == null){
			wasDeployCommand=new WasDeployCommand(this);
		}
		return wasDeployCommand;	
	}
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getServerName() {
		return serverName;
	}
	public void setServerName(String serverName) {
		this.serverName = serverName;
	}
	public StringBuffer getOutputBuffer() {
		 if(outputBuffer == null)
			 outputBuffer = new StringBuffer();
	        return outputBuffer;
	}
	public void setOutputBuffer(StringBuffer outputBuffer) {
		this.outputBuffer = outputBuffer;
	}
	public StringBuffer getErrorBuffer() {
		if(errorBuffer == null)
			errorBuffer = new StringBuffer("");
        return errorBuffer;
	}
	public void setErrorBuffer(StringBuffer errorBuffer) {
		this.errorBuffer = errorBuffer;
	}
	public boolean isRunning() {
		return running;
	}
	public void setRunning(boolean running) {
		this.running = running;
	}
	public Calendar getStartTime() {
		return startTime;
	}
	public void setStartTime(Calendar startTime) {
		this.startTime = startTime;
	}
	public Calendar getEndTime() {
		return endTime;
	}
	public void setEndTime(Calendar endTime) {
		this.endTime = endTime;
	}
	public int getErrorCode() {
		return errorCode;
	}
	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}
	public String getAction() {
		return action;
	}
	public void setAction(String action) {
		this.action = action;
	}
	public boolean isRemoteExecute() {
		return remoteExecute;
	}
	public void setRemoteExecute(boolean remoteExecute) {
		this.remoteExecute = remoteExecute;
	}
	public String getHostname() {
		return hostname;
	}
	public void setHostname(String hostname) {
		this.hostname = hostname;
	}
	public String getPort() {
		return port;
	}
	public void setPort(String port) {
		this.port = port;
	}
	public boolean isSecurity() {
		return security;
	}
	public void setSecurity(boolean security) {
		this.security = security;
	}
	public void clearOutput(){
		outputBuffer = null;
	}
	public void clearError(){
		errorBuffer = null;
	}
	public String getScriptPath() {
		return scriptPath;
	}
	public void setScriptPath(String scriptPath) {
		this.scriptPath = scriptPath;
	}
	public String getServerPrefix() {
		return serverPrefix;
	}
	public void setServerPrefix(String serverPrefix) {
		this.serverPrefix = serverPrefix;
	}
	public String getServerSuffix() {
		return serverSuffix;
	}
	public void setServerSuffix(String serverSuffix) {
		this.serverSuffix = serverSuffix;
	}
	public void clearStartTime() {
		// TODO Auto-generated method stub
		this.startTime=null;
	}
	public void clearEndTime() {
		// TODO Auto-generated method stub
		this.endTime=null;
	}
	public void clearCode() {
		// TODO Auto-generated method stub
		this.errorCode=-1;
	}
	public String getDmgrUsername() {
		return dmgrUsername;
	}
	public void setDmgrUsername(String dmgrUsername) {
		this.dmgrUsername = dmgrUsername;
	}
	public String getDmgrPassword() {
		return dmgrPassword;
	}
	public void setDmgrPassword(String dmgrPassword) {
		this.dmgrPassword = dmgrPassword;
	}
	
	
	
}
